package cn.gyn.gynrpc.core.api;

import lombok.Data;

/**
 * RPC统一异常处理
 */
//@Data :set get
@Data
public class RpcException extends RuntimeException {
    //异常码
    private String errcode;

    public RpcException() {
    }

    public RpcException(String message) {
        super(message);
    }

    public RpcException(String message, Throwable cause) {
        super(message, cause);
    }

    public RpcException(Throwable cause) {
        super(cause);
    }

    public RpcException(Throwable cause, String errcode) {
        super(cause);
        this.errcode = errcode;
    }

    public RpcException(String message, String errcode) {
        super(message);
        this.errcode = errcode;
    }

    //这里约定异常码命名的规则：因为不同异常类型处理方式不同,技术类异常通过重试可能成功，业务类异常无法重试成功
    //X => 技术类异常：比如超时、节点宕机、zk问题等
    //Y => 业务类异常：客户要求转账10元，但账户只有9元，无法转账成功，抛出一个业务类异常
    //Z => unknown,搞不清楚，无法分类，等搞清了再归类到XY
    //定义异常码:异常码-异常信息
    public static final String SocketTimeoutEx = "X001" + "-" + "http_invoke_timeoout";
    public static final String NoSuchMethodEx = "X002" + "-" + "method_not_exists";
    public static final String ExceedLimitEx  = "X003" + "-" + "tps_exceed_limit";
    public static final String UnknownEx = "Z001" + "-" + "unknown";

}
